﻿using System.Collections.Generic;
using System.Linq;

namespace AntJoin.SignalR.Hubs
{

    /// <summary>
    /// 待改成其他的
    /// </summary>
    public class HubUserList
    {
        public long Count => _dictionary.Count;

        private readonly Dictionary<string, string> _dictionary = new Dictionary<string, string>();


        public void Login(string userId, string connectionId)
        {
            _dictionary[userId] = connectionId;
        }

        public void Logout(string userId, string connectionId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                //掉线移除用户
                var user = _dictionary.Values.FirstOrDefault(a => a == connectionId);
                if (user != null)
                {
                    _dictionary.Remove(user);
                }
            }
            else
            {
                _dictionary.Remove(userId);
            }
        }
    }
}
